package com.czm.art_light.service.impl;

import com.czm.art_light.annotation.DistributedLock;
import com.czm.art_light.entity.ArtUserSearchHistory;
import com.czm.art_light.mapper.ArtUserSearchHistoryMapper;
import com.czm.art_light.service.ArtUserSearchHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 历史搜索信息 服务类
 */
@Service
public class ArtUserSearchHistoryServiceImpl implements ArtUserSearchHistoryService {
    @Autowired
    private ArtUserSearchHistoryMapper artUserSearchHistoryMapper;

    /**
     * 热门搜索记录前10条
     */
    @Override
    public List<String> getHotSearchHistory() {
        return artUserSearchHistoryMapper.getHotSearchHistory();
    }

    /**
     * 添加搜索记录
     */
    @DistributedLock(
            prefix = "addSearchHistory",
            lockKey = "#artUserSearchHistory.searchKeyword"
    )
    @Override
    public void addSearchHistory(ArtUserSearchHistory artUserSearchHistory) {
        artUserSearchHistoryMapper.insert(artUserSearchHistory);
    }
}
